$(function() {
	//设置活动按钮
	changeHeaderMenu(1);
	changeMenu(1, 2);
	//初始化列表数据
	loadAgent();
	my_bind_check_num('#recharge_num');
//	my_bind_check_num('#recharge_code');
});

function loadAgent() {
    $.getJSON('/fw/agent/agentReg_getlist.action', function(data){
    	var html = '';
    	$.each(data.rows, function(i, r) {
    		if(r.agentName == "admin")
    			return;
    		html += '<option value="' + r.agentIndex + '">' + r.agentName + '</option>';
    	});
    	$('#recharge_agent').html(html);
    });
}

var adding = false;
function sure() {
	if(adding)
		return;
	adding = false;
	var agentIndex  = $("#recharge_agent").val();
	if(!agentIndex){
		alert("请选择代理商!");
		adding = false;
		return;
	}
	var recharge_num = $("#recharge_num").val();
	if(!recharge_num){
		alert("请输入充值点数!");
		adding = false;
		return;
	}
	if(recharge_num < 1 || recharge_num > 50000) {
		alert("充值点数必须在1-50000之间!");
		adding = false;
		return;
	}
	var recharge_code = $("#recharge_code").val();
	if(!recharge_code){
		alert("请输入验证码!");
		adding = false;
		return;
	}
    data = {
		agentIndex: agentIndex,
		point: recharge_num,
		vcode: recharge_code
    };
    var agentName = $("#recharge_agent option:selected").text();
    if(confirm('确定为代理商“' + agentName + '”充值' + recharge_num + '点数？')) {
    	$.getJSON('/fw/agent/agentCon_agentRecharge.action', data, function(data){
    		if(data.success && data.result){
    			$('#alertdiv').savehandle('setmsg',{msg:'充值成功！',timer:2000});
    		}else{
    			$('#alertdiv').savehandle('setmsg',{msg:data.result.errors?data.result.errors:'充值失败！', timer: 2000});
    		}
    		$("#recharge_num").val('');
    		$("#recharge_code").val('');
    		changeVc();
    		adding = false;
    	});
	}
}

function changeVc(){
	$('.vcimg').attr('src','/fw/common/verify_graphCode.action?_dc' + Math.random());
}
